package com.until;

import java.util.concurrent.Semaphore;

public class Testsemophore {
    public static void main(String[]args){
        final Semaphore semaphore = new Semaphore(3);

        for (int i=0;i<7;i++)
        {
            new Thread(new Runnable() {
                public void run() {
                    try {
                        semaphore.acquire();
                        System.out.println(Thread.currentThread().getName()+"获取到许可");
                        Thread.sleep(1000);
                        semaphore.release();

                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }).start();
        }


    }

}
